# -*- coding = utf-8 -*-
# @Time : 2020/7/17 15:33
# @Author : gxm

import cv2
import os
from baiduAPIchexingshibie.baiduAPIdemo import chexing_get
from shibie.plate_recognition import plate_recodnition
from parking_database.database_operations import operation_data
from parking_database.insert import clear_slot


def tingcheshuju_get(imgs):
    tingcheshujuji=[]
    for step,img in enumerate(imgs):
        tingcheshuju = {}
        leibie, color, name = chexing_get(img["path"])
        chepai = plate_recodnition(img["img"])
        tingcheshuju["id"] = step
        tingcheshuju["chepai"] = chepai
        tingcheshuju["chexing"] = color + name
        tingcheshuju["path"] = img["path"]
        # tingcheshuju["color"]=color
        # print(tingcheshujuji)
        x = tingcheshuju
        tingcheshujuji.append(x)

        # print(tingcheshujuji)
    return tingcheshujuji

def data_proprecess():
    path = "paddle1/contrib/VehicleDetection/demo"
    imgs = []
    dir = (path)
    dirs = os.listdir(path)
    # 输出所有文件和文件夹
    for img in dirs:
        if not os.path.isdir(img):
            img_p = {}
            img_path = os.path.join(dir, img)
            img = cv2.imread(img_path)
            img_p["path"] = img_path
            img_p["img"] = img
            imgs.append(img_p)

    return imgs



def updata_db(path):
    imgs=data_proprecess(path)
    data = tingcheshuju_get(imgs)
    operation_data(data)






if __name__ == "__main__":
    # imgs=[]
    # dir = ("C:\\Users\\19372\\Desktop\\car_image")
    # dirs = os.listdir("C:\\Users\\19372\\Desktop\\car_image")
    # # 输出所有文件和文件夹
    # for img in dirs:
    #     if not os.path.isdir(img):
    #         img_p={}
    #         img_path = os.path.join(dir, img)
    #         img = cv2.imread(img_path)
    #         img_p["path"]=img_path
    #         img_p["img"]=img
    #         imgs.append(img_p)
    #
    # data=tingcheshuju_get(imgs)
    # operation_data(data)
    #clear_slot()


    # path= ("C:\\Users\\19372\\Desktop\\car_image")
     print(tingcheshuju_get(data_proprecess()))

    # updata_db(path)
    # img=data_proprecess(path)
    # st=tingcheshuju_get(img)
    # print(st)

    # updata_db(path)








    # print(tingcheshuju_get(imgs))



